package com.ibm.sc.osp.sample.job.config;

import com.dangdang.ddframe.job.api.simple.SimpleJob;
import com.dangdang.ddframe.job.event.JobEventConfiguration;
import com.dangdang.ddframe.job.lite.api.JobScheduler;
import com.dangdang.ddframe.job.reg.zookeeper.ZookeeperRegistryCenter;
import com.ibm.sc.osp.common.config.job.JobConfig;
import com.ibm.sc.osp.common.config.properties.JobProperties;
import com.ibm.sc.osp.sample.job.task.SyncJob;
import com.ibm.sc.osp.sample.job.task.TaskJob;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration("job_refresh")
@EnableConfigurationProperties({JobProperties.class})
public class SimpleJobConfig extends JobConfig {
    @Bean
    //定时任务实现类 (第一个任务)
    public SimpleJob syncJob() {
        return new SyncJob();
    }
    
    @Bean
    //(第二个任务)...
    public SimpleJob taskJob() {
        return new TaskJob();
    }
    
    @Bean
    //声明定时任务schedule (第一个任务)
    public JobScheduler syncJobScheduler(
        @Qualifier("syncJob") SimpleJob job, ZookeeperRegistryCenter center,
        JobEventConfiguration eventConfiguration, JobProperties properties) {
        return super.getJobScheduler(job, center, eventConfiguration, properties, "sync");
    }
    
    @Bean
    //声明定时任务schedule (第二个任务)...
    public JobScheduler taskJobScheduler(
        @Qualifier("taskJob") SimpleJob job, ZookeeperRegistryCenter center,
        JobEventConfiguration eventConfiguration, JobProperties properties) {
        return super.getJobScheduler(job, center, eventConfiguration, properties, "task");
    }
}
